Expressibility in the Lambda Calculus with Letrec
نویسندگان
چکیده
Rewriting Systems. An abstract rewriting system (ARS) is a quadruple ⟨A,Φ, src, tgt⟩ consisting of a set A of objects, a set Φ of steps, and src, tgt ∶ Φ → A, the source and target functions. We will always assume that A ∩Φ = ∅. For objects a ∈ A we denote by Φout(a) and by Φin(a) the set of steps in Φ that depart (are outgoing steps) Clemens Grabmayer and Jan Rochel 4 from a, and that arrive (are incoming steps) at a, respectively. We say that an ARS is finite if its set of steps is finite. For ARSs Ai = ⟨Ai,Φi, srci, tgti⟩ for i ∈ {1,2} we say that A1 is a sub-ARS of A2 if A1 ⊆ A2, Φ1 ⊆ Φ2, and src1, tgt1 are the restrictions of src2 and tgt2, respectively, to Φ1, which are required to be total functions (this implies that, for all φ ∈ Φ1, it holds that src2(φ) = src1(φ) ∈ A1, and tgt2(φ) = tgt1(φ) ∈ A1. Induced sub-ARS. For an object a ∈ A of an ARS A = ⟨A,Φ, src, tgt⟩ we denote by (a↠) ∶= ⟨A,Φ, src, tgt⟩ the sub-ARS of A induced by a, where A comprises only the objects from A that are reachable from a by an arbitrary number of steps (or no steps) and with Φ, src, tgt being the restrictions of Φ, src, tgt to the objects in A and to steps between objects in A. Bisimulations between ARSs. Let Ai = ⟨Ai,Φi, srci, tgti⟩ for i ∈ {1,2} be ARSs. A relation B ⊆ (A1 ×A2)∪(Φ1 ×Φ2), which relates objects with objects and steps with steps, is called an ARS-bisimulation if: — if a1 B a2, then B relates each step from a1 to some step from a2 (forth condition), and each step from a2 to some step from a1 (back condition); — if φ1 B φ2 with φ1 ∶ a1 → a′1 and φ2 ∶ a2 → a′2, then a1 B a2 and a′1 B a′2. Labellings of ARSs. Let A = ⟨A,Φ, src, tgt⟩ and A = ⟨A,Φ, src, tgt⟩ be ARSs. (i) An ARS-bisimulation L between A and A is called a labelling of A to A, and A the L-labelled version of A, if the converse L of L is a function L ∶ A ∪Φ → A∪Φ, and if additionally, for all a ∈ A and a ∈ A with a L a, the restriction L ∣Φ′out(a′)∶ Φ′out(a′)→ Φout(a) of L to the steps departing from a is bijective. (ii) A rewrite labelling L of A to A is a pair ⟨L, l⟩ consisting of a labelling L of A to A together with an initial labelling function l mapping objects of A to bisimilar objects of A. Strategies. A history-free strategy for an abstract rewriting system A is a sub-ARS of A that has the same objects, and the same normal forms as A. A history-aware strategy for an abstract rewriting system A is a history-free strategy for the L-labelled version of A with respect to, and together with, a rewrite labelling ⟨L, l⟩ of A. By a strategy for A we will mean a history-free strategy or a history-aware strategy for A. Remark. Let S be a history-aware strategy of A, and let A be that L-labelled version of A which S is a history-free strategy of. Then S projects to a history-free strategy Š of A. The projection is defined by L, which induces a local bijective correspondence of outgoing steps of related sources of A and A. Mind that for deterministic S, Š may become non-deterministic. Furthermore, every rewrite sequence according to S in A projects to a unique rewrite sequence in A (which is a rewrite sequence according to Š). The last mentioned fact makes it possible to speak, for a given rewrite labelling, of rewrite sequences of a history-aware strategy on the objects of the original ARS. Let S be a history-aware strategy for an ARS A, and a an object of A. Suppose that S is a sub-ARS of the L-labelled version A of A for some rewrite labelling ⟨L, l⟩ of A. Then by a rewrite sequence of S on a (in A) we will mean the projection to A of a rewrite sequence of S (in A) on the result l(a) of the initial labelling applied to a. Expressibility in the Lambda Calculus with letrec 5 Rewrite relations: notation and properties. For the single-step rewrite relation induced by an ARS we use the arrow symbol → possibly subscripted with appropriate names. Let → ⊆ A × A be a rewrite relation. We denote by ↠ the many-step rewrite relation induced by →, by which we mean the reflexive and transitive closure of →. By → we denote the one-or-more-step rewrite relation of →, the transitive closure of →. By → we mean the zero-or-one-step rewrite relation of →, the reflexive closure of →. By a normal form of → we mean an a ∈ A such that there is no a ∈ A with a→ a. By → we mean the reduction to normal form rewrite relation induced by →, the restriction of ↠ to a relation with the normal forms of → as codomain: → = {⟨a, a⟩ ∣ a↠ a, a is normal form of →}. The rewriting properties below are reformulations, and some are slight variations, of known properties of rewrite relations. Definition 2.1. Let →1, →2, →3 be rewrite relations. The rewrite relation →1 is called cofinal for →2 if ↠2 ⊆↠1 ⋅↞2. We say that →1 is cofinal for →2 with trailing →3-steps if ↠2 ⊆↠1 ⋅↞3. Furthermore we say that →1 factors into →2 and →3 if →1 ⊆→2 ⋅→3. We will several times use the following specific version of König’s Lemma. König’s Lemma. Let G = ⟨V, E⟩ be an undirected graph with set V of vertices and set E of edges. Suppose that G has infinitely many vertices (V is infinite), that it is connected (for all vertices v,w ∈ V there exists a path in G from v to w) and that every vertex has finite degree (it is adjacent to only finitely many other vertices in G). Then for every vertex v ∈ V , G contains an infinitely long simple path from v, that is, a path starting at v without repetition of vertices.† Combinatory Reduction Systems. Many of the formalisations we introduce are based on the framework of Combinatory Reduction Systems (CRSs) (Klop, 1980), (Klop et al., 1993) (Terese, 2003, Sec. 11.3), and, in particular, on infinitary Combinatory Reduction Systems (iCRSs) (Ketema and Simonsen, 2011). Infinite CRSs. When speaking of ‘infinite terms’ for CRSs over some signature we draw on (Terese, 2003, 12.4) and (Ketema and Simonsen, 2011) where meta-terms of iCRSs are defined by means of metric completion. The metric is defined on α-equivalence classes of finite preterms dependent on the minimal depth at which two finite preterms belonging to the equivalence classes have a ‘conflict’. The objects formed by the metric completion process can be represented as equivalence classes of infinite preterms, we call them iCRS-preterms, with respect to a notion of α-equivalence that again is based on the notion of ‘conflict’ (see also (Terese, 2003, Def. 12.4.1)). Hereby iCRS-preterms are infinite ordered dyadic trees in which each node is either labelled by a variable name, and then the node does not have a successor, or by named abstractions λx (with some † This formulation corresponds to the following original formulation by Dénes König on page 80 in (König, 2001): “Satz 3: Jeder unendliche zusammenhängende Graph G endlichen Grades besitzt einen einseitig unendlichen Weg, wobei der Anfangspunkt P0 dieses Weges beliebig vorgeschrieben werden kann.” This in connection with the definition on page 10 in (König, 2001): “Eine unendliche Menge von Kanten PiPi+1 (i = 0,1,2, . . . in inf.), bzw. der durch sie gebildete Graph, heißt ein einseitig unendlicher Weg, falls für i ≠ j stets Pi ≠ Pj ist.” Clemens Grabmayer and Jan Rochel 6 const c = c s[x ∶= c] = t[y ∶= c] [] [x]s = [y]t s1 = t1 . . . . . . sn = tn f f(s1, . . . , sn) = f(t1, . . . , tn) Fig. 2. Schroer-style proof system A∞(Σ) for α-equivalence of iCRS-preterms over signature Σ: for every f ∈ Σ with arity n, A∞(Σ) contains a rule f . In instances of the rule [] , the constant c is chosen fresh for s and t. Substitution which occurs in the assumption of [] denotes substitution by variable replacement on iCRS-preterms. It needs not to be capture-avoiding because of the freshness of the substituant. variable name x), and then the node has a single successor node, or by an abstraction symbol, and then the node has a right and a left successor node. For denoting infinite preterms (and later terms) we use, as much as possible, usual notation for dealing with finite terms. A slight exception is our use, in certain situations, of a finite-CRS-based notation for infinite λ-terms that are not λletrec-expressible (e.g. see Example 4.25). By iCRS-terms we will mean α-equivalence classes of iCRS-preterms. The notion of α-equivalence on iCRS-preterms based on the absence of conflicts can be described by provability in the proof system A∞(Σ) in Figure 2 which is a variant of a proof system due to Schroer (see (Hendriks and van Oostrom, 2003)). Definition 2.2 (α-equivalence for iCRS preterms, Schroer-style proof system). The proof system A∞(Σ) for α-equivalence on iCRS-preterms over signature Σ consists of the axioms and rules displayed in Figure 2, each of which contains a rule f for every f ∈ Σ. Provability in A∞(Σ) of an equation between preterms is defined as the existence of a possibly infinite, completed derivation: for example, by ⊢A∞ s = t we mean the existence of a possibly infinite prooftree D with conclusion s = t such that maximal threads from the conclusion upwards either have length ω, or have finite length and end at a leaf that carries an axiom 0. (We will generally use the decorated turnstyle symbol ⊢ to indicate provability by completed, possibly infinite derivations.) However, closer to coinductive proof systems for infinite λ-terms that we develop is the following different, but equivalent characterisation of α-equivalence for infinite iCRS-preterms, a variant for iCRS-terms of a proof system for α-equivalence between finite λ-terms due to Kahrs (see (Hendriks and van Oostrom, 2003)). Definition 2.3 (α-equivalence for iCRS preterms, Kahrs-style proof system). The proof system A∞(Σ) for α-equivalence on iCRS-preterms over signature Σ consists of the axioms and the rules in Figure 3 with, for every f ∈ Σ, a rule f . Provability of an equation between preterms in A∞(Σ) is defined, analogously as in 2, as the existence of a possibly infinite, completed derivation. This formulation of α-equivalence for infinite λ-terms will be the key to our formulation of a ‘coinduction principle’ for infinite λ-terms in Theorem 9.7. Infinite rewrite relation. For an iCRS with rewrite relation →, we denote by ↠ the infinitary rewrite relation induced by strongly convergent and continuous rewrite Expressibility in the Lambda Calculus with letrec 7 0 {x⃗y}y = {z⃗u}u {x⃗}s = {z⃗}t S (if y does not occur in s, and w does not occur in t) {x⃗y}s = {z⃗w}t {x⃗y}s = {z⃗u}t [] {x⃗}[y]s = {z⃗}[u]t {x⃗}s1 = {y⃗}t1 . . . . . . {x⃗}sn = {y⃗}tn f {x⃗}f(s1, . . . , sn) = {y⃗}f(t1, . . . , tn) Fig. 3. Kahrs-style proof system A∞(Σ) for α-equivalence on iCRS-preterms over signature Σ: for every f ∈ Σ with arity n, A∞(Σ) contains a rule f . sequences of arbitrary (countable) ordinal length. Hereby strong convergence means that, at every limit ordinal, the rewrite activity in the terms of the rewrite sequence tends to infinity. Continuity means that the terms of the rewrite sequence converge, in the metric space of infinite terms, at every limit ordinal. By → we will denote the rewrite relation induced by strongly continuous →-rewrite sequences of length ω. Labelled transition systems, labelled transition graphs. A labelled transition system (LTS) is a triple L = ⟨S, A,↣⟩ consisting of a set S of states, a set A of labels, and a set ↣ ⊆ S ×A × S of A-labelled transitions. Labelled transitions ⟨s1, a, s2⟩ ∈ S ×A × S will be indicated as s1 a → s2. A labelled transition graph (LTG) G is a pointed LTS, that is, G = ⟨S, A, x,↣⟩ where ⟨S, A,↣⟩ is an LTS, and x ∈ S, which is called the initial state. Bisimulation between LTSs, LTGs. Let L1 = ⟨S1, A,→1⟩ and L2 = ⟨S2, A,→2⟩ be a LTSs over a common set of labels. A bisimulation on L is a binary relation R ⊆ S1 × S2 that satisfies, for all s ∈ S1 and t ∈ S2: (i) if s R t and s a →1 s, then there exists t ∈ S2 such that t a →2 t and s R t; (ii) if s R t and t a →2 t, then there exists s ∈ S1 such that s a →1 s and s R t. Two states s ∈ S1 and t ∈ S2 are bisimilar, denoted by s↔ t, if there exists a bisimulation R such that s R t. Two LTGs G1 = ⟨S1,A, x1,→1⟩ and G1 = ⟨S2,A, x2,→2⟩ are bisimilar if there is a bisimulation on the underlying LTSs that relates the initial state x1 of G1 with the initial state x2 of G2. 3. The λ-calculus and the λletrec-calculus This section provides the definitions for terms in the λ-calculus and the λletrec-calculus that we will be using througout this work. We define CRS signatures and a rewriting system R▽ for unfolding λletrec-terms to obtain infinite λ-terms. Definition 3.1 (first-order representation of λ and λletrec). Let X = {x0, x1, x2, . . .} be a set of variable names for λ-abstractions, and R be a set of names for recursion variables. We will use x, y, z as syntactical variables for variable names bound by λabstraction, and f , g, h for recursion variable names; and similarly, we will use L, P , Q Clemens Grabmayer and Jan Rochel 8 for terms. The set of λletrec-terms is inductively defined by the following grammar: (term) L ∶∶= λx.L (abstraction) ∣ LL (application) ∣ x (variable) ∣ letrecB inL (letrec) (binding group) B ∶∶= f1 = L . . . fn = L (equations) (f1, . . . , fn ∈R all distinct) The set of λ-terms is defined by a reduced form of the grammar with the letrec alternative and the binding group rule left out. On this grammar the following rules describe unfolding of λletrec-terms in an informal manner: (%▽) ∶ letrecB inL0L1 → (letrecB inL0) (letrecB inL1) (%▽) ∶ letrecB in λx.L0 → λx.letrecB inL0 (% ▽ ) ∶ letrecB0 in letrecB1 inL → letrecB0,B1 inL (% ▽ ) ∶ letrecB in fi → letrecB inLi (if B is f1 = L1 . . . fn = Ln) (% ▽ ) ∶ letrec f1 = L1 . . . fn = Ln inL → letrec fj1 = Lj1 . . . fjn′ = Ljn′ inL (if fj1 , . . . , fjn′ are the recursion variables reachable from L) (% ▽ ) ∶ letrec inL → L The names of the first four rules are chosen to reflect the kind of term that resides inside of the in-part of the letrec-term, which helps to see that the rules are complete in the sense that every term of the form letrecB inL is a redex. We will use higher-order notation and rules to reason about the λ-calculus and the λ-calculus with letrec, which immediately validates our results for α-equivalence classes instead of just preterms. Remark 3.2 (infinitary rewriting). We use CRSs as a rewriting framework since until now infinitary rewriting theory has only been developed for CRSs yet (Ketema and Simonsen, 2009; Ketema and Simonsen, 2010; Ketema and Simonsen, 2011). For formulating the above rules as a CRS, we provide CRS-signatures for λ and λletrec. Definition 3.3 (CRS signatures for λ and λletrec). The CRS-signature for λ consists of the set Σλ = {app, abs} where app is a unary and abs a binary function symbol. The CRS-signature Σλletrec consists of the countably infinite set Σλletrec = Σλ ∪ {letn, rec-inn ∣ n ∈ N} of function symbols, where, for n ∈ N, the symbols letn and rec-inn have arity n. By Ter(λ) and Ter(λletrec) we denote the set of closed CRS-terms over Σλ and Σλletrec respectively, with the restriction that — the symbols letn and rec-inn only occur as patterns of the form letn([f1 . . . fn]rec-inn(M1, . . . ,Mn,M)) for some terms M1, . . . ,Mn,M ∈ Ter(λ) — and that otherwise a CRS abstraction can only occur directly beneath an abs-symbol. Expressibility in the Lambda Calculus with letrec 9 Ter(λ) and Ter(λletrec) will later be specified more formally in Definition 6.1 and Definition 6.2. We will use M , N , O used as syntactical variables for terms in Ter(λ). And by Ter(λletrec) we denote the set of CRS-terms over Σλ, for which we will use the symbols L, P , Q as syntactical variables. Example 3.4. The term in Example 1.1 in CRS notation: abs([a]abs([b]app(abs([c]app(abs([d]app(. . . , c)), b)), a))) Example 3.5. The terms in Example 1.2 in CRS notation: abs([x] let1([r]rec-in1(app(app(∶, x), r))), r) abs([x] let1([r]rec-in1(app(app(∶, x), app(app(∶, x), r)), r))) Definition 3.6 (terms in λ∞). We denote by Ter((λ∞)) the set of finite and infinite CRS-terms over the signature Σλ. Note that the set of infinite λ-terms subsume finite λ-terms, thus whenever we speak of an infinite λ-term in fact we refer to a potentially infinite λ-term. Definition 3.7 (CRS for unfolding in λletrec). The CRS R▽ for unfolding λletrec-terms is the CRS for terms over the signature Σλletrec (see Definition 3.3) with the following rule schemes in which n varies among numbers in N : (%▽) ∶ letn([f⃗]rec-inn(X1(f⃗), . . . ,Xn(f⃗), app(Z0(f⃗), Z1(f⃗)))) → app((letn([f⃗]rec-inn(. . . ,Xn(f⃗), Z0(f⃗)))), (letn([f⃗]rec-inn(. . . ,Xn(f⃗), Z1(f⃗))))) (%▽) ∶ letn([f⃗]rec-inn(X1(f⃗), . . . ,Xn(f⃗), abs([x]Z(f⃗ , x)))) → abs([x] letn([f⃗]rec-inn(X1(f⃗), . . . ,Xn(f⃗), Z(f⃗ , x)))) (% ▽ ) ∶ letn([f⃗]rec-inn(X1(f⃗), . . . ,Xn(f⃗), letm([g⃗]rec-inm(Y1(f⃗ , g⃗), . . . , Ym(f⃗ , g⃗)Z(f⃗ , g⃗))))) → letn+m([f⃗ g⃗]rec-inn+m(X1(f⃗), . . . ,Xn(f⃗), Y1(f⃗ , g⃗), . . . , Ym(f⃗ , g⃗), Z(f⃗ , g⃗))) (% ▽ ) ∶ letn([f⃗]rec-inn(X1(f⃗), . . . ,Xn(f⃗), fi))→ letn([f⃗]rec-inn(X1(f⃗), . . . ,Xn(f⃗),Xi(f⃗))) (% ▽ ) ∶ let0(rec-in0(Z))→ Z (% ▽ ) ∶ letn([f1 . . . fn]rec-inn(X1(fi1,1 , . . . , fim1,1), . . . ,Xn(fi1,n , . . . , fimn,n),) Z(fi1,n+1 , . . . , fimn+1,n+1)) → letn′([fj1 . . . fjn′ ]rec-inn′(Xj1(L1,j1 , . . . , Lmj1 ,j1), . . .) . . .Xjn′ (L1,jn′ , . . . , Lmjn′ ,jn′ ), Z(f1,in+1 , . . . , fimn+1,n+1)) The formulation here of the rule scheme % ▽ for reducing the binding group of a letrec-binding by removing unreachable equations needs additional explanation. On the right-hand side, the terms denoted by the symbol L with different indices are defined as Clemens Grabmayer and Jan Rochel 10 letrec f = letrec g = f g in g in f →▽,rec letrec f = letrec g = f g in g in letrec g′ = f g′ in g′ →▽,letrec letrec f = letrec g = f g in g g′ = f g′ in g ′ →▽,rec letrec f = letrec g = f g in g g′ = f g′ in f g ′ →▽,rec letrec f = letrec g = f g in g g′ = f g′ in (letrec g ′′ = f g′′ in g′′) g′ →▽,@ (letrec f = letrec g = f g in g g′ = f g′ in letrec g ′′ = f g′′ in g′′) (letrec f = letrec g = f g in g g′ = f g′ in g ′) →▽,letrec (letrec f = letrec g = f g in g g′ = f g′ g′′ = f g′′ in g′′) (letrec f = letrec g = f g in g g′ = f g′ in g ′) Fig. 4. Unbounded growth of the binding group in a →▽-rewrite sequence on a λletrec-term that does not contain →▽,red-steps.
منابع مشابه
Expressibility in the Lambda Calculus with Mu
We address a problem connected to the unfolding semantics of functional programming languages: give a useful characterization of those infinite λ-terms that are λletrec-expressible in the sense that they arise as infinite unfoldings of terms in λletrec, the λ-calculus with letrec. We provide two characterizations, using concepts we introduce for infinite λ-terms: regularity, strong regularity, ...
متن کاملSimulation in the Call-by-Need Lambda-Calculus with Letrec, Case, Constructors, and Seq
This paper shows equivalence of several versions of applicative similarity and contextual approximation, and hence also of applicative bisimilarity and contextual equivalence, in LR, the deterministic call-by-need lambda calculus with letrec extended by data constructors, case-expressions and Haskell’s seq-operator. LR models an untyped version of the core language of Haskell. The use of bisimi...
متن کاملSimulation in the Call-by-Need Lambda-Calculus with letrec
This paper shows the equivalence of applicative similarity and contextual approximation, and hence also of bisimilarity and contextual equivalence, in the deterministic call-by-need lambda calculus with letrec. Bisimilarity simplifies equivalence proofs in the calculus and opens a way for more convenient correctness proofs for program transformations. Although this property may be a natural one...
متن کاملCorrectness of Copy in Calculi with Letrec, Case, Constructors and Por
This paper extends the internal frank report 28 as follows: It is shown that for a call-by-need lambda calculus LRCCPλ extending the calculus LRCCλ by por, i.e in a lambda-calculus with letrec, case, constructors, seq and por, copying can be done without restrictions, and also that call-by-need and call-by-name strategies are equivalent w.r.t. contextual equivalence.
متن کاملExpressibility in the Lambda Calculus with
We address a problem connected to the unfolding semantics of functional programming languages: give a useful characterization of those infinite λ-terms that are λletrec-expressible in the sense that they arise as infinite unfoldings of terms in λletrec, the λ-calculus with letrec. We provide two characterizations, using concepts we introduce for infinite λ-terms: regularity, strong regularity, ...
متن کاملEquivalence of Call-By-Name and Call-By-Need for Lambda-Calculi with Letrec
We develop a proof method to show that in a (deterministic) lambda calculus with letrec and equipped with contextual equivalence the call-by-name and the call-by-need evaluation are equivalent, and also that the unrestricted copy-operation is correct. Given a let-binding x = t, the copy-operation replaces an occurrence of the variable x by the expression t, regardless of the form of t. This giv...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید
ثبت ناماگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید
ورودعنوان ژورنال:
- CoRR
دوره abs/1208.2383 شماره
صفحات -
تاریخ انتشار 2012